<% layout('/layouts/default.html', {title: '任务管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnRefresh" title="刷新页面"><i class="fa fa-refresh"></i> 刷新页面</a>
				<% if(hasPermi('schedule:task:edit')){ %>
					<a href="${ctx}/schedule/task/form" class="btn btn-default btnTool" title="新增作业调度"><i class="fa fa-plus"></i> 新增</a>
				<% } %>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${task}" action="${ctx}/schedule/task/listData" method="post" class="form-inline hide">
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">查询</button>
					<button type="reset" class="btn btn-default btn-sm">重置</button>
				</div>
			</#form:form>			
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'任务名称', name:'jobName', index:'a.job_name', width:100, align:"left", frozen:true, formatter: function(val, obj, row, act){
			return '<a href="${ctx}/schedule/task/form?id=1&jobClassName='+row.jobClassName+'&jobName='+row.jobName+'&jobGroup='+row.jobGroup+'" class="btnList" data-title="编辑任务">'+(val||row.id)+'</a>';
		}},
		{header:'任务描述', name:'jobDescription', width:110, align:'left'},
		{header:'调用目标', name:'jobClassName', width:130, align:'left'},
		{header:'周期表达式', name:'cronExpression', width:90, align:'center'},
		{header:'状态', name:'jobStatus', width:50, align:'center'},
		{header:'操作', name:'actions', width:110, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [], params = 'jobClassName='+encodeURIComponent(row.jobClassName)+'&jobGroup='+encodeURIComponent(row.jobGroup);
			<% if(hasPermi('schedule:task:edit')){ %>
				if (row.jobStatus == 'PAUSED'/*暂停*/){
					actions.push('<a href="${ctx}/schedule/task/resume?'+params+'" class="btnList" title="恢复作业" data-confirm="确认要恢复该作业吗？"><i class="fa fa-play"></i></a>&nbsp;');
				}else{
					actions.push('<a href="${ctx}/schedule/task/pause?'+params+'" class="btnList" title="暂停作业" data-confirm="确认要暂停该作业吗？"><i class="fa fa-pause"></i></a>&nbsp;');
				}
				actions.push('<a href="${ctx}/schedule/task/form?id=1&jobClassName='+row.jobClassName+'&jobName='+row.jobName+'&jobGroup='+row.jobGroup + '" class="btnList" title="编辑作业"><i class="fa fa-pencil"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/schedule/task/delete?'+params+'" class="btnList" title="删除作业" data-confirm="确认要删除该作业吗？"><i class="fa fa-trash-o"></i></a>&nbsp;');
			<% } %>
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
$("#btnRefresh").click(function(){
	js.showMessage("页面已刷新。");
	location = "${ctx}/schedule/task/list";
});
</script>